import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		authStatus: false,//是否授权 false:未授权
		loginType: false,//账号登陆状态（判断是否登陆） false:没登录
		userInfo: {},//用户信息
	},
	mutations: {
		login(state, provider) {
			state.authStatus = true;
			state.loginType = true;
			state.userInfo = provider;
			uni.setStorage({ //缓存用户信息
				key: 'userInfo',
				data: state.userInfo
			})
			uni.setStorage({ //缓存用户授权状态
				key: 'authStatus',
				data: state.authStatus
			})
			uni.setStorage({ //缓存用户登陆状态
				key: 'loginType',
				data: state.loginType
			})
		},
		logout(state) {
			state.authStatus = false;
			state.userInfo = {};
			uni.removeStorage({
				key: 'userInfo'
			})
			uni.removeStorage({
				key: 'authStatus'
			})
		}
	},
	actions: {

	}
})

export default store
